﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Activity.Projeto.Model;

namespace Activity.Projeto.Service
{
    public abstract class BaseService
    {
        public void save(BaseModel model)
        {
            try
            {
                validate(model);
                if (model.Codigo > 0)
                {
                    update(model);
                }
                else
                {
                    model.Ativo = true;
                    insert(model);
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }

        protected abstract bool insert(BaseModel model);

        protected abstract bool update(BaseModel model);

        public abstract bool delete(BaseModel model);

        protected abstract void validate(BaseModel model);
    }
}
